# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: team/kde <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-plasma
pkgname=kwin
pkgver=6.0.4.1
pkgrel=0
pkgdesc="An easy to use, but flexible, composited Window Manager"
# armhf blocked by qt6-qtdeclarative
arch="all !armhf"
url="https://kde.org/plasma-desktop/"
license="GPL-2.0-or-later AND (GPL-2.0-only OR GPL-3.0-only) AND LGPL-2.1-only"
depends="
	hwdata
	kirigami
	qt6-qtmultimedia
	qt6-qtwayland
	xwayland
	"
depends_dev="$pkgname
	breeze-dev
	eudev-dev
	fontconfig-dev
	kcmutils-dev
	kcompletion-dev
	kconfig-dev
	kconfigwidgets-dev
	kcoreaddons-dev
	kcrash-dev
	kdeclarative-dev
	kdecoration-dev
	kglobalaccel-dev
	ki18n-dev
	kiconthemes-dev
	kidletime-dev
	kio-dev
	knewstuff-dev
	knotifications-dev
	kpackage-dev
	krunner-dev
	kscreenlocker-dev
	kservice-dev
	ksvg-dev
	ktextwidgets-dev
	kwayland-dev
	kwidgetsaddons-dev
	kwindowsystem-dev
	kxmlgui-dev
	lcms2-dev
	libdrm-dev
	libepoxy-dev
	libinput-dev
	libplasma-dev
	libqaccessibilityclient-dev
	libxcvt-dev
	libxi-dev
	libxkbcommon-dev
	mesa-dev
	mesa-gbm
	pipewire-dev
	plasma-activities-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtsensors-dev
	wayland-dev
	xcb-util-cursor-dev
	xcb-util-image-dev
	xcb-util-wm-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kdoctools-dev
	kglobalacceld-dev
	kpipewire-dev
	libcap-utils
	libdisplay-info-dev
	plasma-wayland-protocols
	qt6-qttools-dev
	samurai
	"
checkdepends="xvfb-run"

case "$pkgver" in
	*.90*) _rel=unstable;;
	*) _rel=stable;;
esac
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc $pkgname-lang"
_repo_url="https://invent.kde.org/plasma/kwin.git"
source="https://download.kde.org/stable/plasma/${pkgver%.*}/kwin-$pkgver.tar.xz
	0001-kwin-Fix-building-of-tests.patch
	"
# Broken, fails to setup due to missing or invalid XDG_RUNTIME_DIR?
options="!check"

build() {
	# significantly reduce debug symbol size
	# use None here to not make cmake pass bare -g (-g2)
	CFLAGS="$CFLAGS -O2 -g1" CXXFLAGS="$CXXFLAGS -O2 -g1" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib
	cmake --build build
}

check() {
	XDG_RUNTIME_DIR="$(mktemp -p -d "$builddir")" \
	xvfb-run ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# We don't ship systemd
	rm -r "$pkgdir"/usr/lib/systemd

	# kwin_wayland has CAP_SYS_NICE set. Because of this, libdbus doesn't trust the
	# environment and ignores it, causing for example keyboard shortcuts to not work
	# Remove CAP_SYS_NICE from kwin_wayland to make them work again

}
sha512sums="
a38605dea13a225220544b77f835bff5bb191861ad34dd5ea6de06069921bc6db1f2683cb361d421ab3f7a82c58d2ff914512074a17e8e554bac3e5303f19ab5  kwin-6.0.4.1.tar.xz
14c4ddceca2ef51a139319bdd64bc84d7a1df7c6419e86bdbb04572be3212ca46f5c25cd61fa3b511d7644046f92a07408e472e41d95aab93ec494138a09c1a9  0001-kwin-Fix-building-of-tests.patch
"
